package com.example.fw;

import java.util.Properties;

public class ApplicationManager {
	
	private static ApplicationManager singleton;
		
	private WebDriverHelper webDriverHelper;
	private GroupHelper groupHelper;
	private ContactHelper contactHelper;
	private NavigationHelper navigationHelper;
	private DataBaseHelper dataBaseHelper;

	private Properties props;

	private HibernateHelper hibernateHelper;

	public static ApplicationManager getInstance() {
		if (singleton == null) {
			singleton = new ApplicationManager();		
		}
		return singleton;
	}	
	
	public WebDriverHelper getWebDriverHelper() {
		if (webDriverHelper == null) {
			webDriverHelper = new WebDriverHelper(this);
		}
		return webDriverHelper;
	}
	
	public void stop() {
		if (getWebDriverHelper() != null) {
			webDriverHelper.stop();		
		}
	}

	public GroupHelper getGroupHelper(){
		if (groupHelper == null) {		
			groupHelper = new GroupHelper(this);
		} 
		return groupHelper;
	}
	
	public ContactHelper getContactHelper(){
		if (contactHelper == null) {		
			contactHelper = new ContactHelper(this);
		} 
		return contactHelper;
	}
	
	public NavigationHelper getNavigationHelper(){
		if (navigationHelper == null) {		
			navigationHelper = new NavigationHelper(this);
		} 
		return navigationHelper;
	}

	public DataBaseHelper getDataBaseHelper(){
		if (dataBaseHelper == null) {		
			dataBaseHelper = new DataBaseHelper(this, getProperty("url", "jdbc:mysql://localhost/addressbook?user=root&password="));
		} 
		return dataBaseHelper;
	}
	
	public HibernateHelper getHibernateHelper(){
		if (hibernateHelper == null) {		
			hibernateHelper = new HibernateHelper(this);
		} 
		return hibernateHelper;
	}	
	
	public void setProperties(Properties props) {
		this.props = props;
	}
	
	public String getProperty(String key, String defaultValue){
		return props.getProperty(key, defaultValue);
	}

}
